import json

with open('.nojekyll', mode='w', encoding='utf-8') as f:
    f.write('This file prevents Jekyll build.')

with open('sensitive_list.json', mode='r', encoding='utf-8') as f:
    sensitive_list = json.load(f)


from output_modules import generators, html_wrapper

indexes = []

for word in sensitive_list['words']:
    for generator in generators:
        file_path = generator['path_prefix'] + word['name'] + generator['file_suffix']
        indexes.append((generator['name'] + '/' + word['name'], file_path))
        word_alternatives = word[generator['name'] + '_alternatives']
        file_content = generator['file_wrapper'](
            word_alternatives[0], 
            "\n".join(map(generator['method'], word_alternatives))
        )
        with open(file_path, mode='w', encoding='utf-8') as f:
            f.write(file_content)


def html_a_list_item(name: str, href: str):
    return f'<li><a href="{href}">{name}</a></li>'

index_file_content = html_wrapper(
    'Sensitive words test',
    '<ul>' +
    '\n'.join([ f'<li><a href="{i[1]}">{i[0]}</a></li>' for i in indexes ]) +
    '</ul>'
)

with open('index.html', mode='w') as f:
    f.write(index_file_content)
